<template>
  <view class="">
	  <cu-custom bgColor="" :isBack="true">
	      <block slot="backText">返回</block>
	      <block slot="content"></block>
	  </cu-custom>
	  
	   <view class="margin-top-xl padding">
		   <view class="top-rule margin-top padding text-center">
		   	<text class="text-white text-xxl">修改密码</text>
		   </view>
		   <view class="example">
		   	<uni-forms ref="form" :value="user" labelWidth="80px">
		   	  <uni-forms-item name="oldPassword" label="旧密码">
		   	    <uni-easyinput type="password" v-model="user.oldPassword" placeholder="请输入旧密码" />
		   	  </uni-forms-item>
		   	  <uni-forms-item name="newPassword" label="新密码">
		   	    <uni-easyinput type="password" v-model="user.newPassword" placeholder="请输入新密码" />
		   	  </uni-forms-item>
		   	  <uni-forms-item name="confirmPassword" label="确认密码">
		   	    <uni-easyinput type="password" v-model="user.confirmPassword" placeholder="请确认新密码" />
		   	  </uni-forms-item>
		   	  <!-- <button type="primary" @click="submit">提交</button> -->
		   	</uni-forms>
		   </view>
		   <view class="padding bg-white bottom-rule" style="background-color: #F3F4F6;">
		   	<uni-grid :column="2" :show-border="false" >
		   		<uni-grid-item style="height: 150rpx;">
		   			<view class="padding">
		   				<button class="bg-white text-black" @click="reset">
		   					<!-- <uni-icons type="phone-filled"></uni-icons> -->
		   					<text class="text-xl">重置</text>
		   				</button>
		   			</view>
		   		</uni-grid-item>
		   		<uni-grid-item style="height: 150rpx;">
		   			<view class="padding">
		   				<button class="bg-grey" @click="submit">
		   					<!-- <uni-icons type="closeempty" color="#fff" ></uni-icons> -->
		   					<text class="text-xl">提交</text>
		   				</button>
		   			</view>
		   		</uni-grid-item>
		   	</uni-grid>
		   </view>
	   </view>
	
	
	
    
  </view>
</template>

<script>
  import { updateUserPwd } from "@/api/system/user"

  export default {
    data() {
      return {
        user: {
          oldPassword: undefined,
          newPassword: undefined,
          confirmPassword: undefined
        },
        rules: {
          oldPassword: {
            rules: [{
              required: true,
              errorMessage: '旧密码不能为空'
            }]
          },
          newPassword: {
            rules: [{
                required: true,
                errorMessage: '新密码不能为空',
              },
              {
                minLength: 6,
                maxLength: 20,
                errorMessage: '长度在 6 到 20 个字符'
              }
            ]
          },
          confirmPassword: {
            rules: [{
                required: true,
                errorMessage: '确认密码不能为空'
              }, {
                validateFunction: (rule, value, data) => data.newPassword === value,
                errorMessage: '两次输入的密码不一致'
              }
            ]
          }
        }
      }
    },
    onReady() {
      this.$refs.form.setRules(this.rules)
    },
    methods: {
	reset(){
			this.user.confirmPassword = ""
			this.user.newPassword = ""
			this.user.oldPassword = ""
		},
      submit() {
        this.$refs.form.validate().then(res => {
          updateUserPwd(this.user.oldPassword, this.user.newPassword).then(response => {
            this.$modal.msgSuccess("修改成功")
          })
        })
      }
    }
  }
</script>

<style lang="scss">
  page {
    background-color: #ffffff;
  }
  
  .top-rule {
      height: 140rpx;
      line-height: 140rpx;
      padding: 0px 40rpx;
      background-color:#3C96F3;
      border-radius: 16px 16px 0 0;
      // box-shadow: 0px 16px 26px rgba(0, 0, 0, .8);
    }
	.bottom-rule {
	    height: 140rpx;
	    line-height: 140rpx;
	    padding: 0px 40rpx;
	    // background-color:#3C96F3;
	    border-radius: 0 0 16px 16px;
	    // box-shadow: 0px 16px 26px rgba(0, 0, 0, .8);
	  }
 .example {
    padding: 15px;
    background-color: #F3F4F6;
  }
  // .pwd-retrieve-container {
  //   padding-top: 36rpx;
  //   padding: 15px;
  // }
</style>
